﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using CustomsSystem.BLL;
using CustomsSystem.Model;
using System.Collections.Generic;
using Maticsoft.Common;
namespace WEB.score
{
    public partial class scoreEdit : System.Web.UI.Page
    {
        SheetInfoManage sheetInfoManage = new SheetInfoManage();
        ScoreManage scoreManage = new ScoreManage();
        CustomsSystem.Model.sheetInfo mySheetInfo = new CustomsSystem.Model.sheetInfo();
        CustomsSystem.Model.Score myScore = new CustomsSystem.Model.Score();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)   //评价
                {
                    int id = Convert.ToInt32(Request.QueryString["ID"]);
                    mySheetInfo = sheetInfoManage.GetModel(id);
                    myScore = scoreManage.GetModel(id);
                    Session["scoreID"] = mySheetInfo.sheetID;
                    sheetID.Text = Session["scoreID"].ToString();                 
                }
                else
                {
                    Response.Write("<script>alert('没有对应的委托单!')</script>");
                }
                if (scoreManage.Exists(mySheetInfo.sheetID) == true)
                {
                    Response.Write("<script>alert('己评价!')</script>");
                    Response.Write("<script>window.document.location.href='/Client/ClientSheetView.aspx'</script>");
                }
            }
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            ScoreManage manage = new ScoreManage();
            CustomsSystem.Model.Score myScore = new CustomsSystem.Model.Score();
            //=========有效性判断============
            string strErr = "";
            if (SelectScore1.Checked == true)
            {
                myScore.score = 1;
            }
            else if (SelectScore3.Checked == true)
            {
                myScore.score = 3;
            }
            else if (SelectScore4.Checked == true)
            {
                myScore.score = 4;
            }
            else if (SelectScore5.Checked == true)
            {
                myScore.score = 5;
            }
            else
            {
                strErr = "请选择分数！ \\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            myScore.suggest = TextArea1.Value;
            myScore.sheetID = Convert.ToInt32(Session["scoreID"]);
            if (manage.Exists(myScore.sheetID) == false)
            {
                manage.Add(myScore);
                Response.Write("<script>alert('己提交!')</script>");
                Response.Write("<script>window.document.location.href='/Client/ClientSheetView.aspx'</script>");
            }
        }
    }
}